<template>
	<view>
		<u-navbar title="选择房源" @rightClick="rightClick" :autoBack="true" :placeholder="true">
			<view class="" slot="right">
				<u-icon name="search" size="25"></u-icon>
			</view>
		</u-navbar>
		<view class="house_box">
			<u-cell-group :border="false" v-if="recordList.length != 0">
				<u-cell v-for="(item, index) in recordList" :key="item.id" icon="clock" :title="item.name"
					:isLink="true" @click="gotoaddhouse(item)">
				</u-cell>
			</u-cell-group>
			<u-empty v-if="recordList.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import {
		getHouse
	} from "@/api/home/index.js"

	export default {
		data() {
			return {
				recordList: []
			}
		},
		created() {
			this.getHistory()
		},
		methods: {
			gotoaddhouse(item) {
			   uni.setStorageSync('info', JSON.stringify(item))
				uni.redirectTo({
					url: "../index?info=" + JSON.stringify(item),
				})
			},

			rightClick() {
				uni.redirectTo({
					url: "/pages/public/search/index",
				})
			},
			async getHistory() {
				const res = await getHouse()
				if (res.data.code != 200) return uni.showToast({
					title: '获取历史搜索失败',
					icon: 'none'
				})
				this.recordList = res.data.data
			}
		}
	}
</script>

<style>

</style>